<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="functest.*" %>

<!DOCTYPE HTML>
<html>
<head>
	<meta charset="UTF-8">
	<title>选择路线</title>
	<script type="text/javascript" src="js/jquery-3-2-1.js"></script>
	<link type="text/css" rel="stylesheet" href="layui/css/layui.css" media="all">
	<script type="text/javascript" src="layui/layui.all.js"></script>
	<link type="text/css" rel="stylesheet" href="css/style.css" media="all">
</head>

<body background="img/background.png">
<%
	String name = request.getParameter("name");
	String userid = request.getParameter("userid");
	String tkid = request.getParameter("tkid");
%>
<div class="main">
	<div class="head" >
		<div class="head-text">
			<li class="title">航空票务系统</li>
		</div>
		<a href="index.jsp"><img class="logo" src="img/logo.png" ></a>
	</div>
	<div class="content">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			<legend>选择您的路线</legend>
		</fieldset>
		<form action="functest/SelHB<%
			if (name != null){
			    out.println("?name="+name+"&userid="+userid + "&tkid=" + tkid);
			}
		%>" class="layui-form" style="margin-left: 16%" id="select" name="select" method="post" >
			<div class="layui-form-item">
				<label class="layui-form-label">出发地</label>
				<div class="layui-input-inline">
					<select id="cityname" name="cityname" lay-verify="required" lay-filter="cityname">
						<option value="0">请选择出发城市</option>
						<%
							FindAPrint func =new FindAPrint();
							List<String> cityname=func.Findcitys();
							for(String attribute : cityname) {
								out.println("<option value=\""+attribute+"\">"+
										attribute+"</option>");
							}
						%>
					</select>
				</div>
				<div class="layui-input-inline">
					<select id="jcname" name="jcname" lay-filter="jcname">
						<option value="0">-请选择出发机场</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">目的地</label>
				<div class="layui-input-inline">
					<select id="cityname1" name="cityname1" lay-filter="cityname1">
						<option value="0">-请选择到达城市</option>
						<%
							FindAPrint func1 =new FindAPrint();
							List<String> cityname1=func.Findcitys();
							for(String attribute : cityname1) {
								out.println("<option value=\""+attribute+"\">"+
										attribute+"</option>");
							}
						%>
					</select>
				</div>
				<div class="layui-input-inline">
					<select id="jcname1" name="jcname1" lay-filter="jcname1">
						<option value="0">-请选择到达机场</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">出发时间</label>
				<div class="layui-input-inline">
					<select id="month" name="month" lay-filter="month">
						<option value="0">-选择出发月</option>
						<%	String x=null;
							for(int i=1;i<13;i++) {
								x=String.valueOf(i);
								out.println("<option value=\""+x+"\">"+
										x+"月</option>");
							}
						%>
					</select>
				</div>
				<div class="layui-input-inline">
					<select name="day" id="day" lay-filter="day">
						<option value="0">-请选择出发日</option>
					</select>
				</div>
			</div>

			<div class="layui-form-item" style="margin-right:19%;text-align: center;">
				<input type="submit" class="layui-btn" name="select" value="查询" />
			</div>

		</form>
	</div>
</div>
<footer class="tail">
	<p>Designed By @没有对象的野指针,@Irony,@Aumorose
</footer>
</body>
<script type="text/javascript">
    layui.use(['form','layer'],function (){
        var form = layui.form
            ,layer = layui.layer;
        form.render();
        form.on('select(cityname)', function(data){
            var cityname = data.value; //得到被选中的值
            $.ajax({
                url:"functest/getjc",
                type:"post",
                dataType:"html",
                timeout:"1000",
                data:{cityname:cityname},
                success:function(data){

                    $("#jcname option").remove();
                    var jc=data.split(",");
                    for ( var i = 0; i < jc.length; i++) {
                        var jcName = jc[i];
                        $("#jcname").append(
                            "<option value="+jcName+">"
                            + jcName + "</option>");
                    }
                    form.render('select');
                },
                error : function(XMLResponse) {
                    alert(XMLResponse.responseText);
                }
            });
        });
        form.on('select(cityname1)', function(data){
            var cityname1 = data.value; //得到被选中的值
            $.ajax({
                url:"functest/getjc",
                type:"post",
                dataType:"html",
                timeout:"1000",
                data:{cityname:cityname1},
                success:function(data){

                    $("#jcname1 option").remove();
                    var jc=data.split(",");
                    for ( var i = 0; i < jc.length; i++) {
                        var jcName = jc[i];
                        $("#jcname1").append(
                            "<option value="+jcName+">"
                            + jcName + "</option>");
                    }
                    form.render('select');
                },
                error : function(XMLResponse) {
                    alert(XMLResponse.responseText);
                }
            });
        });
        form.on('select(month)', function(data){
            var month=document.getElementById("month");
            var day=document.getElementById("day");


            $("#day").empty();
            day.add(new Option("-请选择出发日","0"),undefined);
            for(var i=1;i<=31;i++)
            {	var x=i.toString();
                day.add(new Option(x+"日",x),undefined);

            }
            if(month.value=="2")
            {
                day.options.remove(29);
                day.options.remove(29);
                day.options.remove(29);
            }
            else if(month.value=="4" ||month.value=="6"||month.value=="9"
                ||month.value=="11")
            {
                day.options.remove(31);
            }
            day.options.remove(0);
            form.render('select');
        });
    })
</script>

</html>
